<?php

$CI =& get_instance();
$CI->load->database();
$CI->load->library("front/header_lib");
$query_pages = $CI->db->get_where('bur_staticpages',array('staticpage_link'=>'design_directory'));
foreach($query_pages->result() as $row_vals)
{
    $title = $row_vals->staticpage_title;
	$metakey_page = $row_vals->staticpage_metakey;
    $metadesc_page = $row_vals->staticpage_metadesc;
}
$CI->header_lib->display_header_element(array("script"=>array("jquery-1.4.2","jquery.validate.pack","jquery.NobleCount.min","ajaxfileupload","si.files"),"page_title"=>$title,"metakey_page"=>$metakey_page,"metadesc_page"=>$metadesc_page));

$datas[''] = '';

$CI->header_lib->display_header($datas);

$data['company_info'] = 1 ;
$CI->load->model('Directory_company_model');
//echo $CI->session_user_id;
$count = $CI->Directory_company_model->get_view_count($CI->session_user_id);
$listing_active = $CI->Directory_company_model->get_listing_status($CI->session_user_id);

$data['view_count'] = $count['view_count'];
$data['lead_count'] = $count['lead_count'];
$left_class['company_info'] = 1;
?>

<script type="text/javascript" src="<? echo site_url();?>/js/jquery.maskedinput-1.0.js"></script>
<style type="text/css" title="text/css">
.SI-FILES-STYLIZED label.cabinet
{
    width: 100px;
    height: 28px;
    background: url(<?php echo base_url()?>image/select_image.jpg) 0 0 no-repeat;
    display: block;
    overflow: hidden;
    cursor: pointer;
}

.SI-FILES-STYLIZED label.cabinet input.file
{
    position: relative;
    height: 100%;
    width: auto;
    opacity: 0;
    -moz-opacity: 0;
    filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);
	z-index:2;
}



/* Style for jquery validation */
#company_form label.error {
    background-color: #cccc00;
    color: #000;
    padding: 5px 10px;
    width: 320px;
    margin: 0 0 0 0px;
    float: none;
    height:19px;
    line-height:19px;
    position:relative;
    display:block;
    font-weight: normal;
}
</style>
<script type="text/javascript">
SI.Files.stylizeAll();
  $(document).ready(function(){
      var result = true;
        $("#contact_number").mask("(999) 999-9999"); 
      $.validator.addMethod("comapanyCheck", function() {
            $.post("<?php echo site_url('json_request/check_company_json')?>" ,{
                 company: $('#name').val()
            },function(data){
                result = (data=="TRUE") ? true : false;
            }, "json");
                return result;
      });
      
      /* $("#company_form").submit(function()
       
       if($('#upload'.val() == '' ){
       
       alert('test');
       return false; 
       }
       
       });*/

      $("#company_form").validate({
        onkeyup: false,
        rules: {
            name: {
                required : true,
                comapanyCheck : true
            },
            description : "required",
            contact_number : "required",
            contact_email : "email",
            province_id : "required"
         

        },
        messages: {
            name: {
                required : "Please input a Name",
                comapanyCheck : "Duplicate  name exists in directory"
            },
            description : "Please input a  Description",
            contact_number : "Please input a Telephone Number for customers",
            contact_email : "Please input the valid email address",
            province_id : "Please select a Province/Region"
            
        }
      });

$('#text_detail').NobleCount('#count_detail',{
	max_chars: 5000,
	block_negative: true
});

   
  });
 
// function upload jquery
function ajaxFileUpload_gif(){ 

if($('#upload-1').val()=="" || $('#upload-1').val()==undefined){
$('.gif_create_error').css('display','block');
return false;
}else if($('#upload-2').val()=="" || $('#upload-2').val()==undefined){
$('.gif_create_error').css('display','block');
return false;
}else
 if($('#upload-3').val()=="" || $('#upload-3').val()==undefined){
$('.gif_create_error').css('display','block');
return false;
}else
if($('#upload-4').val()=="" || $('#upload-4').val()==undefined){
$('.gif_create_error').css('display','block');
return false;
}else{

    $("#loading")
    .ajaxStart(function(){
        $(this).show();
    })
    .ajaxComplete(function(){
        $(this).hide();
    });
     $.ajax({
      url: "<?php echo site_url('ajax_upload/upload_directory_gif/')?>/image1/1/image2/2/image3/3/image4/4",
      global: false,
      type: "POST",
      data: ({name : $('#name').val(),image1 : $('#upload-1').val() ,image2 :$('#upload-2').val(),image3: $('#upload-3').val(),image4: $('#upload-4').val()}),
      dataType: "html",
      async:false,
      success: function(msg){
         $(".addfoto").html('<img src="<?php echo base_url();?>uploads/directory/company_logo/thumb/'+msg
                    +'" width="72" />'
                   +'<input type="hidden" id="upload" name="upload" value="'+msg +'">');
         //alert(msg);
      }
   }
).responseText;
   }
    
    }
function ajaxFileUpload(get_this){
    var this_id = get_this.id.split('_');
    
    if(this_id[1]){
        var div_load = "#loading_" + this_id[1];     
        $(div_load)
        .ajaxStart(function(){
            $(this).show();
        })
        .ajaxComplete(function(){
            $(this).hide();
            $(this).unbind("ajaxStart");
        })    
        .ajaxStop(function(){
            $(this).unbind("ajaxComplete");    
        });
            
        var img = '#img_' + this_id[1];
        $.ajaxFileUpload({
            url:'<?php echo site_url('ajax_upload/upload_directory_image/upload/userprofile/network')?>/<?php echo $company_detail['company']?>/file/'+get_this.id,
            secureuri:false,       
            fileElementId: get_this.id,
            dataType: 'json',
            success: function (data, status){
                if(typeof(data.error) != 'undefined'){
                    if(data.error != ''){                    
                        $(img).html(data.error);
                    }else{                        
                        $(img).html('<img src="<?php echo base_url();?>uploads/directory/userprofile/thumb/'+data.msg+'" width="75" /><br />'
                        +'<input type="hidden" name="upload[]" value="'+data.msg +'"><br />'
                        +'<input type="hidden" name="upload_ori[]" value="'+data.ori +'">');
                    }
                }
            },
            error: function (data, status, e){
                $(img).html(e);
            }
        });
    
    }else{
        var this_id = get_this.id.split('-');
        var div_load = "#loading-" + this_id[1];
     
        $(div_load)
        .ajaxStart(function(){
            $(div_load).show();
        })
        .ajaxComplete(function(){
            $(div_load).hide();
            $(this).unbind("ajaxStart");
        })
        .ajaxStop(function(){
            $(this).unbind("ajaxComplete");    
        });    
        
        var img = '#img-' + this_id[1];
        $.ajaxFileUpload({            
            url:'<?php echo site_url('ajax_upload/upload_directory_image/upload/userprofile/network')?>/<?php echo $company_detail['company']?>/file/'+get_this.id,
            secureuri:false,       
            fileElementId: get_this.id,
            dataType: 'json',
            success: function (data, status){
                if(typeof(data.error) != 'undefined'){
                    if(data.error != ''){                    
                        $(img).html(data.error);
                    }else{
                        $(img).html('<img src="<?php echo base_url();?>uploads/directory/userprofile/thumb/'+data.msg+'" width="75" /><br />'                                               
                        +'<input id="upload-' + this_id[1] +'" type="hidden" value="'+data.msg +'"><br />'
                        +'<input type="hidden" id="upload_ori-'+ this_id[1] +'" value="'+data.ori +'">');
                    }
                }
            },
            error: function (data, status, e){
                $(img).html(e);
            }
        });  
    }    
}

function clear_logo(){
    $("#info").html('<img src="<?php echo base_url()?>xhtml/img/forlogo2.gif" width="160" height="160">'
    + '<input type="hidden" name="upload" value="">');
    return false;
}
</script>
<!--body content starts-->
<div id="container_wrapper">
	
    	<div class="left_part">

            <?php echo $CI->header_lib->display_panel_left($data);?>
        </div>

        <div class="right_part">
       		<div class="wright">
                	<h2 style="display:none">
                <?php
                if(!empty($company_detail['company'])){
                	echo $company_detail['company'];
                }else{
                	echo "Company name not defined yet";
                }
                ?></h2>

                <?php if ($messageBox != ''):?>
                <br/>
                <div style="background-color:#CF118C; color:#FFF; font-size:14px; margin-bottom:5px; padding:5px;"><?php echo $messageBox;?></div>
                <?php endif;?>
       		 <?php
                $attributes = array('id' => 'company_form');
                echo form_open_multipart('register/company',$attributes);?>

            <div class="email_section001">
            	<ul>
                	<li>
                    	<div class="list_div031"><h3 class="style18">Your details</h3></div>
                    	<div class="list_div04"><p style="padding-top:5px;" class="txt12">Screen Name: <span>(Required)</span></p></div>
                        <div class="clear"></div>
                   	</li>
                    <li>
                    	<div class="list_div031">
                        <div class="height10"></div>
                        <p class="redTxt12">Input your details here to DISPLAY on your advert in the directory.</p>
                    	</div>
                    	<div class="list_div04">
                        <?php
                        $input_company = array('name' => 'name','id' => 'name', 'class' => 'large_input', 'value' => set_value('name',$company_detail['company']));
                        echo form_input($input_company);//form_input('name',$company_detail['company']); ?>
                        <?php echo form_error('name','<p id="error_recaptcha" class="inform f12 error_message"><strong>Error:</strong>','</p>') ?>
                        </div>
                        <div class="clear"></div>
                   	</li>
                    <li>
                    	<div class="list_div031">
                        <div class="height10"></div>
                        <div class="height50"></div>
                        <p style="font-size:14px;">You have <strong id="count_detail" class="redTxt12">5000</strong> characters left</p></div>
                    	<div class="list_div04">
                        <p class="txt12">Description: <span>(Required)</span></p>
                        <div class="height10"></div>
                        <?php echo form_textarea(array('name'=>'description', 'class' => 'textarea_style','id'=>'text_detail'),set_value('description',$company_detail['company_description'])); ?>
                <?php echo form_error('description','<p id="error_recaptcha" class="inform f12 error_message"><strong>Error:</strong>','</p>') ?>
                        <div class="height10"></div>
                        <ul>
                            	<li>
                            	  <p class="txt12">Telephone Number: <span>(Required)</span></p></li>
                                <li>
                                <?php echo form_input(array('name'=>'contact_number','id' => 'contact_number'),$this->session->userdata('telephone')); ?>
                <?php echo form_error('contact_number','<p id="error_recaptcha" class="inform f12 error_message"><strong>Error:</strong>','</p>') ?></li>
                                <li>
                                  <p class="txt12">Fax Number: <span>(optonal)</span></p></li>
                                <li>
                                <?php echo form_input('fax_number',set_value('fax_number',$company_detail['fax_number'])); ?>
                <?php echo form_error('fax_number','<p id="error_recaptcha" class="inform f12 error_message"><strong>Error:</strong>','</p>') ?></li>
                                <li>
                                  <p class="txt12">Email: <span>(optional)</span></p></li>
                                <li>
                                 <?php  echo form_input('contact_email',$this->session->userdata('email')); ?>
                <?php echo form_error('contact_email','<p id="error_recaptcha" class="inform f12 error_message"><strong>Error:</strong>','</p>') ?>
                                </li>
                                <li>
                                  <p class="txt12">Website: <span>(optional)</span></p></li>
                                <li>
                                <?php
                if(empty($company_detail['company_website'])){
                    $website = 'http://';
                }else{
                    $website = 'http://'.$company_detail['company_website'];
                }

                echo form_input('website',set_value('website',$website)); ?>
                <?php echo form_error('website','<p id="error_recaptcha" class="inform f12 error_message"><strong>Error:</strong>','</p>') ?>
                </li>
                            </ul>
                        </div>
                        <div class="clear"></div>
                   	</li>
                  </ul>
            </div>
<div class="height10"></div>
            <div class="email_section001">
            	<ul>
                	<li>
                    	<div class="list_div031"><h3 class="style18">location info</h3></div>
                    	<div class="list_div04">
                    	  <p class="txt12">cities : <span>(Required)</span></p></div>
                        <div class="clear"></div>
                   	</li>
                    <li>
                    	<div class="list_div031">
                        <div class="height10"></div>
                        <p class="redTxt12">Geographical location for fast directory filtering.</p>
                    	</div>
                    	<div class="list_div04">
                        	<select name="province_id">
                                <option value="">Select cities</option>
                              
                            <?php if(!empty($region_list)){
                              foreach($region_list as $key =>$value){
                             if($value['country'] == '2541')
                            $region_list_1[] = $value;
                            
                            if($value['country'] == '2540')
                            $region_list_2[] = $value;
 
                                             }
                            }
                            if(!empty($region_list_1)): ?><optgroup label="Standard Cities" >
                                <?php foreach($region_list_1 as $key=>$value): ?>
                                <option value="<?php echo $value['id']?>" <?php echo ($company_detail['region_id']==$value['id'])?'selected':'';?>><?php echo $value['name'] ?></option>
                                <?php endforeach;?></optgroup>
                                <?php endif;
                             if(!empty($region_list_2)): ?><optgroup label="International Cities" >
                                <?php foreach($region_list_2 as $key=>$value): ?>
                                <option value="<?php echo $value['id']?>" <?php echo ($company_detail['region_id']==$value['id'])?'selected':'';?>><?php echo $value['name'] ?></option>
                                <?php endforeach;?></optgroup>
                                <?php endif;
                            
                            ?> 
                              
                                <?php
                                
                                /*if(!empty($region_list)): ?>
                                <?php foreach($region_list as $key=>$value): ?>
                                <option value="<?php echo $value['id']?>" <?php echo ($company_detail['region_id']==$value['id'])?'selected':'';?>><?php echo $value['name'] ?></option>
                                <?php endforeach;?>
                                <?php endif;*/ ?>
                                </select>
                                <?php echo form_error('province_id','<p id="error_recaptcha" class="inform f12 error_message"><strong>Error:</strong>','</p>') ?>
                            <div class="height10"></div>
                            <ul>
                            	<li>
                            	  <p class="txt12">Town: <span>(Optional)</span></p></li>
                                <li>
                                <?php echo form_input(array('name'=>'city_name'),set_value('city_name',$company_detail['city_name'])); ?>
                <?php echo form_error('city_name','<p id="error_recaptcha" class="inform f12 error_message"><strong>Error:</strong>','</p>') ?>
                </li>
                           </ul>
                        </div>
                        <div class="clear"></div>
                   	</li>
                  </ul>
            </div>
           
                <div class="clear"></div>
           
            <div class="height10"></div>
            <div class="email_section001">
            	<p><b>Click  to create your animated profile picture</b> </p><br />
                <div class="addfoto">
    <!--<div id="add_image"></div>-->
    <?php for($i=1;$i<=4;$i++){?>
    <div class="labelf">
        <br>
        <strong class="purple">Image <?php echo $i;?>:</strong>
        <br><br><br>
       
    </div><!-- labelf -->
    <div class="fotor" style="position: relative">
        <!-- ie show button -->
        <div class="select_label">
        <?php /*if (isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false)):?>
            <input name="file-<?php echo $i;?>" class="file" type="file" id="file-<?php echo $i;?>" onchange="return ajaxFileUpload(this);"/>
        <?php else: */  ?>
            <label class="cabinet"> 
                <input name="file-<?php echo $i;?>" class="file" type="file" id="file-<?php echo $i;?>" onchange="return ajaxFileUpload(this);"/>
            </label>
        <?php //endif;?> 
        </div>
        <div style="float:left; position:relative"><img id="loading-<?php echo $i;?>" src="<?php echo base_url()?>image/loading_blue.gif" style="display:none;position:absolute;z-index:1000;" /></div>
        <div id="img-<?php echo $i;?>" class="select_image"> 
            <!--<img src="<?php //echo base_url()?>xhtml/img/blank3.gif" width="75" height="75">-->             
        </div>
        
         
    </div><!-- fotor -->
    
    <div class="clear"></div>
    <?php }?>
    <label class="gif_create_error error"  style="display: none;">Please upload image to create animated profile photo.</label>
    <input type="button" name="Create" value="Create" onclick="ajaxFileUpload_gif();" />
<div class="clear"></div>

</div>
                <div class="clear"></div>
            </div>
           <div class="line"></div>
           <?php
                $form_button = array(
                  'type'=>'submit',
                  'name'=>'submit',
                  'value'=>'submit',
                  'content'=>'Submit',

                );
                echo form_button($form_button) ?>
                 <?php echo form_close(); ?>

                </div>
    	</div>

<?php $this->load->view(TEMPLATE_NAME.'/front/side_right'); ?>
     <div class="clear"></div>

</div>
<!--body content ends-->


<?php
$CI->load->library("front/footer_lib");
$CI->footer_lib->display_footer();
$CI->footer_lib->display_footer_element();

?>